<?php


namespace app\controller\Web;

use app\service\Web\PlanService;
use support\Request;
use Throwable;
use app\util\ResponseTrait;

use hg\apidoc\annotation as Apidoc;

/**
 * @Apidoc\Title("方案")
 */
class PlanController
{
    use ResponseTrait;

    /**
     * @Apidoc\Url("/web/plan/getList")
     * @Apidoc\Title("列表")
     * @Apidoc\Method("GET")
     * @Apidoc\Query(ref="pagingParam")
     * @Apidoc\Query("lang",type="string",require=false,default="",desc="语言类型【需写接口】")
     * @Apidoc\Query("keyword",type="string",require=false,default="",desc="关键字（标题、短标题、内容）")
     * @Apidoc\Query("industry_id",type="int",require=false,default="",desc="行业ID")
     * @Apidoc\Query("scene_id",type="int",require=false,default="",desc="场景ID")
     * @Apidoc\Query("industry_ids",type="string",require=false,default="",desc="行业ID-多选【逗号分隔】")
     * @Apidoc\Query("scene_ids",type="string",require=false,default="",desc="场景ID-多选【逗号分隔】")
     * @Apidoc\Query("platform",type="string",require=false,default="",desc="平台类型【需写接口】")
     * @Apidoc\Query("is_top",type="int",require=false,default="",desc="是否置顶（10是、20否）")
     * @Apidoc\Returned(ref="pagingResponse")
     * @Apidoc\Returned("list",type="array", require=false, default="[]",desc="方案列表",table="plan",children={
     *      @Apidoc\Returned("industry",type="object", require=false, default="{}",desc="行业",table="industry",field="id,name"),
     *      @Apidoc\Returned("scene",type="object", require=false, default="{}",desc="场景",table="scene",field="id,name")
     * })
     */
    public function getList(Request $request){
        try {
            $where = [];
            $page = parameterCheck($request->input('page'), 'int', 1);
            $pageSize = parameterCheck($request->input('pageSize'), 'int', 10);

            $where['is_show'] = 10;
            $where['industry_id'] = parameterCheck($request->input('industry_id'), 'float', 0);
            $where['scene_id'] = parameterCheck($request->input('scene_id'), 'float', 0);
            $where['industry_ids'] = parameterCheck($request->input('industry_ids'), 'string', '');
            $where['scene_ids'] = parameterCheck($request->input('scene_ids'), 'string', '');
            $where['keyword'] = parameterCheck($request->input('keyword'), 'string', '');
            $where['platform'] = parameterCheck($request->input('platform'), 'string', '');
            $where['lang'] = parameterCheck($request->input('lang'), 'string', '');
            $where['is_top'] = parameterCheck($request->input('is_top'), 'int', 0);

            $data = PlanService::getList($where, $page, $pageSize);

            return $this->success($data);
        } catch (Throwable $e) {
            return $this->fail($e);
        }
    }

    /**
     * @Apidoc\Url("/web/plan/getInfo")
     * @Apidoc\Title("详情")
     * @Apidoc\Method("GET")
     * @Apidoc\Query("id",type="int",require=true,default="1",desc="方案ID")
     * @Apidoc\ResponseSuccess("data",type="object", table="plan",children={
     *      @Apidoc\Returned("industry",type="object", require=false, default="{}",desc="行业",table="industry",field="id,name"),
     *      @Apidoc\Returned("scene",type="object", require=false, default="{}",desc="场景",table="scene",field="id,name")
     * })
     */
    public function getInfo(Request $request)
    {
        try {
            $where = [];

            $where['id'] = parameterCheck($request->input('id'), 'int', 0);

            $data = PlanService::getOne($where['id']);

            return $this->success($data);
        } catch (Throwable $e) {
            return $this->fail($e);
        }
    }
}